@extends('system.frame_layout')
<?php $parent_menu = "关于我们"; $menu_selected = "在线留言";?>

@section('content')
    <div id="content-panel">
        <div class="row">

            {{-- 在线留言区域 --}}
            <div class="col-md-6 col-xs-12">
                <div class="portlet light bordered">
                    <div class="portlet-title">
                        <div class="caption">
                            <i class="icon-social-dribbble font-dark hide"></i>
                            <span class="caption-subject font-dark bold">在线留言 Online Message</span>
                        </div>
                    </div>
                    <div class="portlet-body">
                        <div class="form-group">
                            <form id="send_message" role="form" action="{{ route('sys.feedback.send') }}" method="post">
                                <div class="form-body">
                                    <input name="_token" value="{{csrf_token()}}" type="hidden"/>
                                    <div class="row input-row">
                                        <label class="col-xs-12 title" for="exampleInputPassword1">
                                            留言内容 - Feedback Content
                                        </label>
                                        <div class="col-xs-12">
                                            <div class="form-group">
                                                <textarea name="message" class="form-control" rows="6"></textarea>
                                                <label for="message" style="float: right;margin-top: 10px;"></label>
                                            </div>

                                        </div>
                                    </div>

                                    <div class="row input-row">
                                        <div class="col-xs-12">
                                            <button type="submit" class="btn blue-madison">
                                                <i class="iconfont icon-duihao"></i>&nbsp;提交留言
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            {{-- 以往咨询列表 --}}
            <div class="col-md-6 col-xs-12">
                @foreach($feedbacks as $feedback)

                    <div class="note note-{{ $feedback->status == 1 ? 'success' : 'danger' }}"
                         style="padding: 15px 30px 25px 15px;">
                        <span style="font-size: 12px;color: #909090;">留言于 {{ date("Y-m-d H:i:s",$feedback->time) }}</span>
                        <h4 class="block">
                            {{ $feedback->content }}
                        </h4>
                        @if(!empty($feedback->reply))
                            <span style="font-size: 12px;color: #909090;">回复于 {{ date("Y-m-d H:i:s",$feedback->reply_time) }}</span>
                            <p>{!! $feedback->reply or '无' !!}</p>
                        @endif
                    </div>
                @endforeach

                @include('system.coms.fenye')
            </div>
        </div>
    </div>
@endsection

@section('footer')
    <script>
        $("#send_message").validate({
            rules: {
                roles: "required",
                message: {
                    required: true
                }
            }, errorPlacement: function (error, element) {
                $(element).closest("form").find("label[for='" + element.attr("name") + "']").html('请填写留言内容');
            },
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        if (data.code == 0) {
                            toastr["success"](data.msg);
                            setInterval(function () {
                                window.location = "{{ route('sys.feedback') }}";
                            }, 1000);
                        } else {
                            toastr["error"](data.msg);
                        }
                    }
                });
            }
        });
    </script>
@endsection